package com.component.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.component.domain.SysRoleEntity;
import com.component.mapper.SysRoleMapper;
import com.component.service.SysRoleService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Xiongx
 * @version 1.0
 * @date 2021/6/11 14:49
 * @since JDK 1.8
 */
@Service("sysRoleService")
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRoleEntity> implements SysRoleService {

    @Override
    public SysRoleEntity getSysRoleEntityByUserName(String userName) {
        LambdaQueryWrapper<SysRoleEntity> sysRoleEntityLambdaQueryWrapper=new LambdaQueryWrapper<>();
        sysRoleEntityLambdaQueryWrapper.eq(SysRoleEntity::getRoleName,userName);
        return super.baseMapper.selectOne(sysRoleEntityLambdaQueryWrapper);
    }



    @Override
    public IPage<SysRoleEntity> page(Integer pageNum, Integer pageSize, String roleNo, String roleName) {
        LambdaQueryWrapper<SysRoleEntity> sysRoleEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(roleNo)){
            sysRoleEntityLambdaQueryWrapper.like(SysRoleEntity::getRoleno,roleNo);
        }
        if(StringUtils.isNotBlank(roleName)){
            sysRoleEntityLambdaQueryWrapper.like(SysRoleEntity::getRoleName,roleName);
        }
        sysRoleEntityLambdaQueryWrapper.orderByDesc(SysRoleEntity::getCreateTime);
        IPage<SysRoleEntity> page=this.baseMapper.selectPage(new Page(pageNum,pageSize),sysRoleEntityLambdaQueryWrapper);
        return page;
    }
}
